<?php

namespace plugins\yifang_backend_account\utils\tags;

class Tag_rbac_role_plugin
{
    /**
     * 选择多选html
     */
    public function getCheckBoxHtml($paramObj="")
    {
        $dataObj=paramsObj();
        $dataObj->request=paramsObj();
        $dataObj->data=paramsObj();

        $final_arr=logInit();
        if($final_arr["error_no"]==0){
            $mixed=parseToArr($paramObj,"mixed",0);
            $params=parseToArr($paramObj,"params",array());
            $messages=parseToArr($paramObj,"messages",array());
            $rules=array(
                'extraData' => '',
            );
            $dataDefault=array();
            $paramsObj=paramsObj();
            $paramsObj->params=$params;
            $paramsObj->mixed=$mixed;
            $paramsObj->rules=$rules;
            $paramsObj->messages=$messages;
            $paramsObj->dataDefault=$dataDefault;
            $checkResult = app("verifyParam")::validatorRequest($paramsObj);
            if($checkResult["error_no"]==0){
                $dataObj->request=$checkResult["result"];
            }else{
                $final_arr=logCallErrorMsg($final_arr,$checkResult);
            }
        }
        if($final_arr["error_no"]==0)
        {
            $condition=app("P_tag_plugin")->parseCondition($dataObj->request->extraData);
            $paramsObj=paramsObj();
            $paramsObj->params=array(
                "field"=>"id,name,pid",
            );
            if($condition && is_array($condition)){
                $paramsObj->params=array_merge($paramsObj->params,$condition);
            }
            $checkResult = app("YifangBackendAccount_S_Admin_rbacRole")->selectData($paramsObj);
            if($checkResult["error_no"]==0){
                $result=$checkResult["result"];
                $result=app("YifangBackendAccount_P_Helper")->recursionArr($result);//递归组装
                $selectMap=array();
                if(isset($condition["selectId"]) && $condition["selectId"] >0){
                    if($final_arr["error_no"]==0)
                    {
                        $paramsObj=paramsObj();
                        $paramsObj->params=array(
                            'id' => $condition["selectId"],
                        );
                        $checkResult=app("YifangBackendAccount_S_Admin_rbacRole")->getParentData($paramsObj);
                        if($checkResult["error_no"]==0){
                            $selectMapResult=$checkResult["result"];
                            $selectMap["id"]=$condition["selectId"];
                            $selectMap["data"]=array_column($selectMapResult,"id");
                        }else{
                            $final_arr=logCallErrorMsg($final_arr,$checkResult);
                        }
                    }
                }
                if($final_arr["error_no"]==0)
                {
                    $result=app("YifangBackendAccount_P_Helper")->recursionToMultihtml($result,$selectMap);  //转换成html
                    $return=array();
                    $return["result"]=$result;
                    $final_arr["result"]=$return;
                }
            }else{
                $final_arr=logCallErrorMsg($final_arr,$checkResult);
            }
        }
        return $final_arr;
    }

    /**
     * 选择选择框html
     */
    public function getSelectHtml($paramObj="")
    {
        $dataObj=paramsObj();
        $dataObj->request=paramsObj();
        $dataObj->data=paramsObj();

        $final_arr=logInit();
        if($final_arr["error_no"]==0){
            $mixed=parseToArr($paramObj,"mixed",0);
            $params=parseToArr($paramObj,"params",array());
            $messages=parseToArr($paramObj,"messages",array());
            $rules=array(
                'extraData' => '',
            );
            $dataDefault=array();
            $paramsObj=paramsObj();
            $paramsObj->params=$params;
            $paramsObj->mixed=$mixed;
            $paramsObj->rules=$rules;
            $paramsObj->messages=$messages;
            $paramsObj->dataDefault=$dataDefault;
            $checkResult = app("verifyParam")::validatorRequest($paramsObj);
            if($checkResult["error_no"]==0){
                $dataObj->request=$checkResult["result"];
            }else{
                $final_arr=logCallErrorMsg($final_arr,$checkResult);
            }
        }
        if($final_arr["error_no"]==0)
        {
            $condition=app("P_tag_plugin")->parseCondition($dataObj->request->extraData);
            $paramsObj=paramsObj();
            $paramsObj->params=array(
                "field"=>"id,name,pid",
            );
            if($condition && is_array($condition)){
                $paramsObj->params=array_merge($paramsObj->params,$condition);
            }
            $checkResult = app("YifangBackendAccount_S_Admin_rbacRole")->selectData($paramsObj);
            if($checkResult["error_no"]==0){
                $result=$checkResult["result"];
                $result=app("YifangBackendAccount_P_Helper")->recursionArr($result);//递归组装
                if(isset($condition["selectId"])){
                    $result=app("YifangBackendAccount_P_Helper")->recursionTohtml($result,$condition["selectId"]);  //转换成html
                }else{
                    $result=app("YifangBackendAccount_P_Helper")->recursionTohtml($result);  //转换成html
                }
                $return=array();
                $return["result"]=$result;
                $final_arr["result"]=$return;
            }else{
                $final_arr=logCallErrorMsg($final_arr,$checkResult);
            }
        }
        return $final_arr;
    }

    /**
     * 获取分类
     */
    public function getData($paramObj="")
    {
        $dataObj=paramsObj();
        $dataObj->request=paramsObj();
        $dataObj->data=paramsObj();

        $final_arr=logInit();
        if($final_arr["error_no"]==0){
            $mixed=parseToArr($paramObj,"mixed",0);
            $params=parseToArr($paramObj,"params",array());
            $messages=parseToArr($paramObj,"messages",array());
            $rules=array(
                'extraData' => '',
            );
            $dataDefault=array();
            $paramsObj=paramsObj();
            $paramsObj->params=$params;
            $paramsObj->mixed=$mixed;
            $paramsObj->rules=$rules;
            $paramsObj->messages=$messages;
            $paramsObj->dataDefault=$dataDefault;
            $checkResult = app("verifyParam")::validatorRequest($paramsObj);
            if($checkResult["error_no"]==0){
                $dataObj->request=$checkResult["result"];
            }else{
                $final_arr=logCallErrorMsg($final_arr,$checkResult);
            }
        }
        if($final_arr["error_no"]==0)
        {
            $condition=app("P_tag_plugin")->parseCondition($dataObj->request->extraData);
            $paramsObj=paramsObj();
            $paramsObj->params=array(
                "field"=>"id,`name`,pid",
            );
            if($condition && is_array($condition)){
                $paramsObj->params=array_merge($paramsObj->params,$condition);
            }
            if(isset($paramsObj->params["pid"])){
                if(!is_numeric($paramsObj->params["pid"])){
                    $paramsObj->params["pid"]=0;
                }
            }else{
                $paramsObj->params["pid"]=0;
            }
            $checkResult = app("YifangBackendAccount_S_Admin_rbacRole")->selectData($paramsObj);
            if($checkResult["error_no"]==0){
                $return=array();
                $return["result"]=$checkResult["result"];
                $final_arr["result"]=$return;
            }else{
                $final_arr=logCallErrorMsg($final_arr,$checkResult);
            }
        }
        return $final_arr;
    }

    public function __call($name,$arguments)
    {
        return recordLogMsgLevelTwo(app("errorLevel")::E_WARNING,app("errorCode")::UNDEFINED_METHOD,lang("sys.noMethodDefined"),$name,$arguments);
    }
}

?>